package com.fzh.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fzh.mapper.MessageMapper;
import com.fzh.pojo.entity.Message;
import com.fzh.pojo.utils.ResponeMessageUtil;
import com.fzh.service.MessageService;

@Service
public class MessageServiceImpl implements MessageService {
	
	@Autowired
	private MessageMapper messageMapper;

	@Override
	public List<Message> queryAllMessage(Integer setValue,Integer limit,String content,String isAnswer,String isPublic) {
		return messageMapper.selectAllMessage(setValue,limit,content,isAnswer,isPublic);
	}

	@Override
	public Integer queryMessageCounts(String content,String isAnswer,String isPublic) {
		return messageMapper.selectMessageCounts(content,isAnswer,isPublic);
	}

	@Override
	public List<Message> queryAllMessageIsAnswer() {
		return messageMapper.selectAllMessageIsAnswer();
	}

	@Override
	public Boolean addMessage(Message message) {
		return ResponeMessageUtil.getResMsg(messageMapper.insertMessage(message));
	}

	@Override
	public Boolean editMessageById(Message message) {
		return ResponeMessageUtil.getResMsg(messageMapper.updateMessageById(message));
	}

	@Override
	public Boolean delAllMessageByIds(String id) {
		String[] split = id.split(",");
		List<String> ids = new ArrayList<>();
		for(int i = 0; i < split.length; i ++) {
			ids.add(split[i]);
		}
		return ResponeMessageUtil.getResMsg(messageMapper.deleteAllMessageByIds(ids));
	}

	@Override
	public Boolean delMessageById(Integer id) {
		return ResponeMessageUtil.getResMsg(messageMapper.deleteMessageById(id));
	}

	@Override
	public Boolean editMessageIsAnswerById(Integer id, Integer num) {
		return ResponeMessageUtil.getResMsg(messageMapper.updateMessageIsAnswerById(id,num));
	}

	@Override
	public Boolean editMessageIsPublicById(Integer id, Integer num) {
		return ResponeMessageUtil.getResMsg(messageMapper.updateMessageIsPublicById(id,num));
	}

	@Override
	public Boolean editMessageContentById(Integer id, String value, Integer num) {
		return ResponeMessageUtil.getResMsg(messageMapper.updateMessageContentById(id,value,num));
	}

	@Override
	public Integer insertMessage(Message message) {
		return messageMapper.insertMessage(message);
	}

	@Override
	public List<Message> selectByProId(Integer id) {
		return messageMapper.selectByProId(id);
	}
	
	

}
